package arithmetic;

public class Selectsort {
	public static void main(String[] args) {
		int[] arr = { 9, 2, 8, 6, 3, 7, 16, 15, 18, 1, 25, 19 };
		sort(arr);
		for (int i : arr) {
			System.out.print(i+" ");
		}
		System.out.println();
	}

	/**
	 * 选择排序
	 */
	private static void sort(int[] arr) {
		// 外层循环控制论轮数
		for (int i = 0; i < arr.length - 1; i++) {
			// 记录当前论述所要安放的下标
			int k = i;
			for (int j = i; j < arr.length; j++) {
				if (arr[k] > arr[j]) {
					k = j;
				}

			}
			int temp = arr[i];
			arr[i] = arr[k];
			arr[k] = temp;
		}
	}
}
